home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 August: Tool Chest / Dev.CD Aug 98 TC.toast / Sample Code / Devices / TradDriverLoaderLib1.0b5 / TestDriver / TestDriverMain.c < prev   
Encoding:
C/C++ Source or Header  |  1997-07-11  |  2.8 KB  |  108 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        TestDriverMain.c
  3.  
  4.     Contains:    Implementation of a very stupid device driver.
  5.  
  6.     Written by:    Quinn "The Eskimo!"
  7.  
  8.     Copyright:    © 1996 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.     You may incorporate this sample code into your applications without
  13.     restriction, though the sample code has been provided "AS IS" and the
  14.     responsibility for its operation is 100% yours.  However, what you are
  15.     not permitted to do is to redistribute the source as "DSC Sample Code"
  16.     after having made changes. If you're going to re-distribute the source,
  17.     we require that you make it clear in the source that the code was
  18.     descended from Apple Sample Code, but that you've made changes.
  19. */
  20.  
  21. #include <Types.h>
  22. #include <Devices.h>
  23.  
  24. static pascal OSErr DRVROpen(ParmBlkPtr paramBlock, DCtlPtr devCtlEnt)
  25. {
  26.     #pragma unused (paramBlock)
  27.     #pragma unused (devCtlEnt)
  28.     return (noErr);
  29. }
  30.  
  31. static pascal OSErr DRVRPrime(ParmBlkPtr paramBlock, DCtlPtr devCtlEnt)
  32. {
  33.     #pragma unused (paramBlock)
  34.     #pragma unused (devCtlEnt)
  35.     return (-1);
  36. }
  37.  
  38. static pascal OSErr DRVRControl(ParmBlkPtr paramBlock, DCtlPtr devCtlEnt)
  39. {
  40.     #pragma unused (paramBlock)
  41.     #pragma unused (devCtlEnt)
  42.     return (controlErr);
  43. }
  44.  
  45. static pascal OSErr DRVRStatus(ParmBlkPtr paramBlock, DCtlPtr devCtlEnt)
  46. {
  47.     #pragma unused (paramBlock)
  48.     #pragma unused (devCtlEnt)
  49.     OSErr err;
  50.     CntrlParamPtr cpb;
  51.     
  52.     cpb = (CntrlParamPtr) paramBlock;
  53.     
  54.     switch ( cpb->csCode ) {
  55.         case 666:
  56.             cpb->csParam[0] = cpb->ioCRefNum;
  57.             err = noErr;
  58.             break;
  59.         default:
  60.             err = statusErr;
  61.     }
  62.     
  63.     return (err);
  64. }
  65.  
  66. static pascal OSErr DRVRClose(ParmBlkPtr paramBlock, DCtlPtr devCtlEnt)
  67. {
  68.     #pragma unused (paramBlock)
  69.     #pragma unused (devCtlEnt)
  70.     return (noErr);
  71. }
  72.  
  73. OSErr main(ParmBlkPtr paramBlock, DCtlPtr devCtlEnt, short dispatch)
  74. {
  75. //
  76. //    Here A4 is already setup to point to our data segment. There is no need
  77. //    to call long oldA4=SetCurrentA4();/SetA4(oldA4); as in code resources.
  78. //
  79. //    However you have to still have to use "#include <SetupA4.h>;RememberA4();..."
  80. //    when using callback functions.
  81. //
  82. // If your routine returns 1 (asynch request can't be completed right away)
  83. // the Metrowerks startup code will correctly jump to jIODone.  You don't need
  84. // to worry about this issue in this driver.
  85. //
  86.     OSErr    err = noErr;
  87.     
  88.     switch(dispatch)
  89.     {
  90.     case 0: //    Open
  91.         err = DRVROpen(paramBlock, devCtlEnt);
  92.         break;
  93.     case 1: //    Prime        return 1 if async request cannot be completed right away
  94.         err = DRVRPrime(paramBlock, devCtlEnt);
  95.         break;
  96.     case 2: //    Control        return 1 if async request cannot be completed right away
  97.         err = DRVRControl(paramBlock, devCtlEnt);
  98.         break;
  99.     case 3: //    Status        return 1 if async request cannot be completed right away
  100.         err = DRVRStatus(paramBlock, devCtlEnt);
  101.         break;
  102.     case 4: //    Close
  103.         err = DRVRClose(paramBlock, devCtlEnt);
  104.         break;
  105.     }
  106.     return err;
  107. }
  108.